/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package helloscala.practise.chapter1

import helloscala.practise.ChapterEntry

object Chapter1Entry extends ChapterEntry {
  def runTests = {

  }

  def testActor = {
    val p: Point = new Point(0.0, 0.0)
    val p1: Point = new Point(1.0, 0.0)
    var p2: Point = new Point(0.0, 1.0)

    p2 = new Point(0.1, 1.0)
    p1.x = 1.1

    ShapeDrawingActor.start()
    ShapeDrawingActor ! new Circle(p, 1.0)
    ShapeDrawingActor ! new Rectangle(p, 2, 5)
    ShapeDrawingActor ! new Triangle(p,
                                     p1,
                                     p2)
    ShapeDrawingActor ! 3.14159

    ShapeDrawingActor ! "exit"
  }

  def testUpper = {
    class Upper {
      def upper(strings: String*): Seq[String] = {
        strings.map((s:String) => s.toUpperCase())
      }
    }

    object UpperSingle {
      def upper(strings: String*) =
        strings.map(_.toUpperCase())
    }

    val up = new Upper
    Console.println(up.upper("a", "First", "sCala", "progrAm"))
    println(UpperSingle.upper("i", "am", "singleton"))
  }

  def testString = {
    object StringUtil {
      def joiner(strings: List[String], separator: String): String =
        strings.mkString(separator)
      def joiner(strings: List[String]): String = joiner(strings, " ")
    }

    val s: String = StringUtil.joiner(List("programming", "scala"))
    println(s)

    //freedom call of a method with param
    println(StringUtil.joiner(List("Programming", "Scala")))
    println(StringUtil.joiner(strings = List("Programming", "Scala")))
    println(StringUtil.joiner(List("Programming", "Scala"), " "))   // #1
    println(StringUtil.joiner(List("Programming", "Scala"), separator = " ")) // #2
    println(StringUtil.joiner(strings = List("Programming", "Scala"), separator = " "))
  }
}
